﻿using Caliburn.Micro;
using System.Collections;
using System;
using System.Collections.ObjectModel;
using System.Windows;
using System.Windows.Media;
using ThunderboltCustomControlLibrary;
using ThunderboltInterfaceSharp.Views.UserControls.Download;
using System.Collections.Generic;
using System.Linq;
using System.Resources;
using System.Windows.Controls;
using System.Globalization;
using System.Xml.Linq;
using System.Reflection;

namespace ThunderboltInterfaceSharp.ViewModels.UserControls.Download;

public class DownloadSidebarViewModel : Screen
{
	public delegate void SwitchForm(Classification title);
	public event SwitchForm SwitchFormEvent;
	public List<IconPathValueButton> ItemCollection { get; set; } = new List<IconPathValueButton>();
	public IconPathValueButton SelectedItem { get; set; }
	public DownloadSidebarViewModel()
	{
	
	}

	protected override void OnViewLoaded(object view)
	{
		var v = (DownloadSidebarView)view;
		ItemCollection = new List<IconPathValueButton>()
		{
			v.BtnDownload,
			v.BtnCompleted,
			v.BtnCloudAddition ,
			v.BtnFilmVault ,
			v.BtnRecycleBin ,
			v.BtnDownloadPersonal ,
			v.BtnCompletedPersonal 
		};
	}
	public void OnSwitchForm(Classification title)
	{
		SwitchFormEvent?.Invoke(title);
	}
	public void SidebarButtonClick(object sender)
	{
		if (sender is IconPathValueButton btn)
		{
			//todo:效率问题，设一个单独的btn对象表示上一次选中的对象
			btn.Background =
				new SolidColorBrush(
					(Color)ColorConverter.ConvertFromString("#2c3138"));
			btn.Foreground = Brushes.DodgerBlue;
			foreach (var btnElse in ItemCollection)
			{
				var a = btnElse.Background.ToString();
				if (btnElse.Name.Equals(btn.Name)) continue;
				if (btnElse.Background.ToString().Equals("#00FFFFFF")) continue;
					btnElse.Background = new SolidColorBrush(
					(Color)ColorConverter.ConvertFromString("Transparent"));
				btnElse.Foreground = Brushes.DarkGray;
			}

			OnSwitchForm((Classification)ItemCollection.IndexOf(btn));
		}
	}
}